var height = $(window).height() > 445 ? $(window).height() : 445;
	$("#container").height(height);
	var bdheight = ($(window).height() - $('#bd').height()) / 2 - 20;
	$('#bd').css('padding-top', bdheight);
	$(window).resize(function(e) {
        var height = $(window).height() > 445 ? $(window).height() : 445;
		$("#container").height(height);
		var bdheight = ($(window).height() - $('#bd').height()) / 2 - 20;
		$('#bd').css('padding-top', bdheight);
    });
	$('select').select();
	var vm = new Vue({
        el: "#main",
        data: {
            merchantId: '',
            username: '',
            password: '',
            captcha: '',
            captchaUrl: '',
            canClick: true,
            choose: true
        },
        methods: {
            login: function(){
                var _this = this;
                _this.username = xmy.trim(_this.username);

                if (_this.username != '') {
                    if (!xmy.chkPhone(_this.username)) {
                        xmy.toast('请输入正确的手机号');
                        return false;
                    }
                } else {
                    xmy.toast("手机号码不能为空");
                    return false;
                }

                _this.password = xmy.trim(_this.password);
                _this.captcha = xmy.trim(_this.captcha);
                _this.merchantId = xmy.trim(_this.merchantId);
                if(_this.canClick){
                    _this.canClick = false;
                    $.ajax({
                        type: "POST",
                        url: api.link + '/sys/login?t=' + xmy.getTime(),
                        data: {
                            merchantId: _this.merchantId,
                            mobile: _this.username,
                            password: _this.password,
                            captcha: _this.captcha
                        },
                        success: function(res){
                            if (res.respCode == "000000") {
                                if (_this.choose) {
                                    xmy.setCookie('choose', _this.choose);
                                    xmy.setCookie('merchantCode', _this.merchantId);
                                    xmy.setCookie('mobile', _this.username);
                                } else {
                                    xmy.setCookie('choose', '');
                                }
                                xmy.setCookie('username', res.data.username);
                                xmy.setCookie('userId', res.data.userId);
                                xmy.setCookie('merchantId',res.data.merchantId);
                                xmy.toast('登录成功');
                                setTimeout(function(){
                                    document.location.href = "./main.html";
                                },1500);
        
                            } else {
                                xmy.toast(res.respMsg);
                                setTimeout(function(){
                                    _this.canClick = true;
                                    _this.getImg();
                                },1500);
                            }
                        },
                        error: function (res) {
                            _this.canClick = true;
                        }
                    })
                }
            },
            getImg: function () {
                this.captchaUrl = api.link + "/captcha.jpg?t=" + xmy.getTime();
            },

            chkuser: function () {
                this.username = parseInt(this.username);
            }
        },
        mounted: function() {
            var _this = this;
            _this.getImg();
            if (xmy.getCookie('choose')) {
                _this.username = xmy.getCookie("mobile");
                _this.merchantId = xmy.getCookie("merchantCode");
            }
            $(document).keydown(function (event) {
                if (event.keyCode == 13) {
                    _this.login();
                }
            });
        }
    })
	$('.loginButton').click(function(e) {
        vm.login();
    });